/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1603.tata.dao.impl;

import edu.fjut.se1603.tata.dao.PetOwnerDao;
import edu.fjut.se1603.tata.entity.Pet;
import edu.fjut.se1603.tata.entity.PetOwner;
import edu.fjut.se1603.tata.util.ConnectMySQL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author admin
 */
public class PetOwnerDaoOracleImpl implements PetOwnerDao{
    
  ConnectMySQL s=new ConnectMySQL();
           Connection conn=s.Connect();

    @Override
    public List<PetOwner> getAllOwners() {
          PetOwner p=null;
           List<PetOwner> l=new ArrayList<PetOwner>();
        try {
            //3执行查询
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("select * from petowner"); //显示pet表中的信息
            //4处理集
            while(rs.next())
            {
                 p=new PetOwner();
                p.setId(rs.getInt(1));
                p.setName(rs.getString("NAME"));
                p.setPassword(rs.getString("PASSWORD"));
                p.setMoney(rs.getInt("MONEY"));
                l.add(p);
                
            }
        } catch (SQLException ex) {
            Logger.getLogger(PetDaoOracleImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return l;
    }

    @Override
    public PetOwner selectid(int id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public PetOwner selectname(String name) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    public void modify(int id,int price)
    {
      try {
          String sql="update petowner set MONEY=? where ID=?";
          PreparedStatement pst=conn.prepareStatement(sql);
          pst.setInt(1,price );
          pst.setInt(2, id);
          pst.executeUpdate();
      } catch (SQLException ex) {
          Logger.getLogger(PetOwnerDaoOracleImpl.class.getName()).log(Level.SEVERE, null, ex);
      }
          
    }
}
